import psicomodelagem.Usuario
class PisicoTagLib {

    static namespace = "wa"

    def ifDevEnv = { attrs, body ->
        def map = grailsApplication.metadata
        String env = map[grailsApplication.ENVIRONMENT]
        if (env == grailsApplication.ENV_DEVELOPMENT) {
            out << body()
        }
    }

    // if pagination...
    def ifPaginate = { attrs, body ->
        def count = attrs.count
        if (params.max && params.max < count) {
            out << body()
        }
    }
    
    // if Usuario logged in...
    def ifUsuario = { attrs, body ->
        boolean valid = session.UsuarioId != null
        if (attrs.not) {
            valid = !valid
        }
        if (valid) {
            out << body()
        }
    }

    
    
    // if Usuario same as logged in Usuario...
    def ifSameUsuario = { attrs, body ->
        boolean valid = session.UsuarioId && session.UsuarioId == attrs.id
        if (attrs.not) {
            valid = !valid
        }
        if (valid) {
            out << body()
        }
    }
    
    // if logged in Usuario owns this item...
    def ifCurrentUsuarioOwns = { attrs, body ->
        boolean valid = session.UsuarioId && session.UsuarioId == attrs.id
        if (attrs.not) {
            valid = !valid
        }
        if (valid) {
            out << body()
        }
    }

   
    
    def UsuarioLink = { attrs ->
		def Usuario = Usuario.get(session.UsuarioId)
        attrs.controller = 'Usuario'
        attrs.action = 'show'
        attrs.id = Usuario.id
        out << "<a href=\"${createLink(attrs).encodeAsHTML()}\""
        // process remaining attributes
        attrs.each { key, value ->
            out << " $key=\"$value\""
        }
        out << '>'
        out << Usuario.name.encodeAsHTML()
        out << '</a>'
    }
    
   
}